// 系统公告
function findSysNotice(CertusJsonAjax, CertusFormAjax, $scope) {
    CertusFormAjax.ajax("isCrcd", {
        "code": "XTGG"
    }, function (response) {
        var data = JSON.parse(response.data);
        var compCode = "";
        $scope.isC = data.isC;
        $scope.isU = data.isU;
        $scope.isD = data.isD;
        if (data.comanyCode == "") {
            compCode = data.baseComp;
        } else {
            compCode = data.comanyCode;
        }
        //系统公告
        var smgColumns = [{
            id: 'content',
            title: '公告内容',
            type: 'string',
            columnClass: 'text-left',
        }, {
            id: 'user_name',
            title: '创建人',
            type: 'string',
            columnClass: 'text-center',
            width: 70
        }, {
            id: 'create_time',
            title: '创建时间',
            type: 'date',
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
            width: 110
        }, {
            id: 'operation',
            title: '操作',
            width: 130,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                if ($scope.isU) {
                    content += '<button class="btn btn-xs btn-info" onclick="edit(' + record.id + ');"><i class="fa fa-edit"></i>  编辑</button>';
                }
                if ($scope.isD) {
                    content += '  ';
                    content += '<button class="btn btn-xs btn-danger" onclick="delMg(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
                }
                return content;
            }
        }];
        CertusJsonAjax.dataInit("findAllSysNotices", {
            "compCode": compCode
        }, smgColumns, 'smgContainer', 'smgToolBarContainer');

        //工作安排
        var wpColumns = [{
            id: 'content',
            title: '内容',
            type: 'string',
            columnClass: 'text-left'
        }, {
            id: 'userName',
            title: '创建人',
            type: 'string',
            columnClass: 'text-center',
            width: 70
        }, {
            id: 'createTime',
            title: '创建时间',
            type: 'date',
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
            width: 110
        }, {
            id: 'operation',
            title: '操作',
            width: 130,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                if ($scope.isU) {
                    content += '<button class="btn btn-xs btn-info" onclick="editWp(\'' + record.id + '\');"><i class="fa fa-edit"></i>  编辑</button>';
                }
                if ($scope.isD) {
                    content += '  ';
                    content += '<button class="btn btn-xs btn-danger" onclick="delWp(\'' + record.id + '\');"><i class="fa fa-trash-o"></i>  删除</button>';
                }
                return content;
            }
        }];
        CertusFormAjax.ajax('findCompPlans2', {
            "compCode": compCode
        }, function (response) {
            var makingOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '工作安排列表',
                datas: response.data,
                columns: wpColumns,
                gridContainer: 'wpContainer',
                toolbarContainer: 'wpToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
            makingGrid.load();
        });
    });

    this.delMg = function (id) {
        layer.confirm('是否确认删除？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax('delMg', {
                "id": id
            }, function () {
                layer.msg("删除成功");
                window.location.reload();
            })
        });
    };

    this.delWp = function (id) {
        layer.confirm('是否确认删除？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax('delWp', {
                "id": id
            }, function () {
                layer.msg("删除成功");
                window.location.reload();
            })
        });
    };
}

// 编辑系统公告
function edit(id) {
    location.href = '#/toEditMg/' + id;
}

function editWp(id) {
    location.href = '#/editWorks/' + id;
}

function findProDynas(CertusJsonAjax) {
    //项目动态
    var smgProColumns = [{
        id: 'pro_name',
        title: '项目名称',
        type: 'string',
        columnClass: 'text-center',
        width: 200
    }, {
        id: 'content',
        title: '项目动态',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'user_name',
        title: '创建人',
        type: 'string',
        columnClass: 'text-center',
        width: 70
    }, {
        id: 'create_time',
        title: '创建时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
        width: 110
    }];
    CertusJsonAjax.dataInit("findProDynas", {}, smgProColumns, 'smgContainer1', 'smgToolBarContainer1');
}

function findPnotice(CertusJsonAjax) {
    //通知消息
    var smgProColumns = [{
        id: 'content',
        title: '通知内容',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'user_name',
        title: '创建人',
        type: 'string',
        columnClass: 'text-center',
        width: 70
    }, {
        id: 'create_time',
        title: '创建时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
        width: 110
    }];
    CertusJsonAjax.dataInit("findPNotices", {}, smgProColumns, 'smgContainer2', 'smgToolBarContainer2');
}